package PAT;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class PAT1021 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        boolean[][] graph = new boolean[n+1][n+1]; // 是否有连线
        for (int i = 0; i < n - 1; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            graph[a][b] = true;
            graph[b][a] = true;
        }
        ArrayList<Integer> ans = new ArrayList<>();
        ArrayList<Integer> ans2 = new ArrayList<>();
        dfs(graph,new boolean[n+1],1,1,-1<<30,ans);
        for (Integer an : ans) {
            dfs(graph,new boolean[n+1],an,1,-1<<30, ans2);
        }
        ans.addAll(ans2);
        HashSet<Integer> integers = new HashSet<>(ans);
        integers.forEach(System.out::println);
    }

    private static void dfs(boolean[][] graph, boolean[] visited, int i, int depth, int maxDepth, ArrayList<Integer> ans) {
        visited[i] = true;
        boolean f  = true; // 是不是叶子节点
        for (int j = 1; j < graph[i].length; j++) {
            if (graph[i][j]&&!visited[j]) {
                f = false;
                break;
            }
        }
        if(f){
            if(maxDepth==depth){
                ans.add(i);
            }else if (maxDepth<depth){
                maxDepth =depth;
                ans.clear();
                ans.add(i);
            }
        }
        for (int j = 1; j < graph[i].length; j++) {
            if(graph[i][j]&&!visited[j]){
                dfs(graph,visited,j,depth+1,maxDepth,ans);
            }
        }
        visited[i] = false;
    }
}
